package com.gxa.service.commnotice.Impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.entity.commnotice.Notice;
import com.gxa.entity.commnotice.Query;
import com.gxa.mapper.commnotice.NoticeMapper;
import com.gxa.service.commnotice.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:37:51
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public int add(Notice notice) {
        return this.noticeMapper.insert(notice);
    }

    @Override
    public int delete(Integer id) {
        return this.noticeMapper.deleteById(id);
    }

    @Override
    public Notice queryById(Integer id) {
        return this.noticeMapper.selectById(id);
    }

    @Override
    public List<Notice> seletAll() {
      return noticeMapper.selectList(null);
    }

    @Override
    public int update(Notice notice) {
        return noticeMapper.updateById(notice);
    }

    @Override
    public List<Notice> queryByCondition(Query query) {
        LambdaQueryWrapper<Notice> lqw = new LambdaQueryWrapper<>();
        //等于
        if (null != query.getNoticeState()){
            lqw.eq(Notice::getNoticeState,query.getNoticeState());
        }
        //大于
        if (null != query.getNoticeStartTime()){
            lqw.ge(Notice::getNoticeStartTime,query.getNoticeStartTime());
        }
        //小于
        if(null != query.getNoticeEndTime()){
            lqw.le(Notice::getNoticeEndTime,query.getNoticeEndTime());
        }
        return noticeMapper.selectList(lqw);
    }


}
